home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 52 / Mac Magazin and MacEasy Magazine CD - Issue 52.iso / Updates / Stata 5.0 Ado-files / ado.sea / newado / svy_dreg.ado < prev    next >
Text File  |  1998-11-22  |  12KB  |  447 lines

  1. *! version 1.2.1  31oct1997
  2. program define svy_dreg  /* display results */
  3.     version 5.0
  4.  
  5.     if      "$S_E_cmd"=="svylogit" { local or "OR" }
  6.     else if "$S_E_cmd"=="svymlog"  { local rrr "RRr" }
  7.  
  8.     local options /*
  9. */ "Level(int $S_level) Prob CI DEFF DEFT MEFF MEFT noHEADer `or' `rrr'"
  10.  
  11.     parse "`*'"
  12.     if "`meff'`meft'"!="" {
  13.         capture di matrix(S_E_meft[1,1])
  14.         if _rc {
  15.             di in red "meff and meft options must be specified " /*
  16.             */ "at initial estimation"
  17.             exit 198
  18.         }
  19.     }
  20.     if `level' < 10 | `level' > 99 {
  21.         local level 95
  22.     }
  23.     if "`prob'`ci'`deff'`deft'`meff'`meft'"=="" {
  24.         local prob "prob"
  25.         local ci   "ci"
  26.     }
  27.  
  28.     local count 2
  29.  
  30.     if "`prob'"!="" {
  31.         local PROB " "
  32.         local count 3
  33.     }
  34.     else local PROB "*"
  35.     if "`ci'"!="" {
  36.         local CI " "
  37.         local count = `count' + 2
  38.     }
  39.     else local CI "*"
  40.     if "`deff'"!="" & `count' < 5 {
  41.         local deff
  42.         local DEFF " "
  43.         local count = `count' + 1
  44.     }
  45.     else local DEFF "*"
  46.     if "`deft'"!="" & `count' < 5 {
  47.         local deft
  48.         local DEFT " "
  49.         local count = `count' + 1
  50.     }
  51.     else local DEFT "*"
  52.     if "`meff'"!="" & `count' < 5 {
  53.         local meff
  54.         local MEFF " "
  55.         local count = `count' + 1
  56.     }
  57.     else local MEFF "*"
  58.     if "`meft'"!="" & `count' < 5 {
  59.         local meft
  60.         local MEFT " "
  61.         local count = `count' + 1
  62.     }
  63.     else local MEFT "*"
  64.  
  65. /* Get estimates. */
  66.  
  67.     tempname t b V
  68.     scalar `t' = invt($S_E_npsu - $S_E_nstr, `level'/100)
  69.     matrix `b' = get(_b)
  70.     matrix `V' = get(VCE)
  71.     local dim = colsof(`b')
  72.  
  73. /* Odds ratio. */
  74.  
  75.     if "`or'"!="" {
  76.         if `dim'==colnumb(`b',"_cons") {
  77.             local dim = `dim' - 1
  78.         }
  79.     }
  80.     else if "`rrr'"!="" { local or rrr }
  81.     else local or "no"  /* make it nonmissing for argument passing */
  82.  
  83. /* Print out header. */
  84.  
  85.     if "`header'"=="" { Header }
  86.  
  87. /* Print out column headers of table 1. */
  88.  
  89.     DashLine
  90.     Colhead `level' `or' " " "`PROB'" "`CI'" /*
  91.     */    "`DEFF'" "`DEFT'" "`MEFF'" "`MEFT'"
  92.  
  93. /* Print out body of table 1. */
  94.  
  95.     DashLine 10
  96.  
  97.     local i 1
  98.     while `i' <= `dim' {
  99.         Body `i' `b' `V' `t' `or' " " "`PROB'" "`CI'" /*
  100.         */    "`DEFF'" "`DEFT'" "`MEFF'" "`MEFT'"
  101.         local i = `i' + 1
  102.     }
  103.  
  104.     DashLine
  105.  
  106. /* See if there is more to print out. */
  107.  
  108.     if "`deff'`deft'`meff'`meft'"=="" {
  109.         FootNote
  110.         exit
  111.     }
  112.  
  113. /* If here, we need to print out another table. */
  114.  
  115.     if "`deff'"!="" { local DEFF " " }
  116.     else local DEFF "*"
  117.     if "`deft'"!="" { local DEFT " " }
  118.     else local DEFT "*"
  119.     if "`meff'"!="" { local MEFF " " }
  120.     else local MEFF "*"
  121.     if "`meft'"!="" { local MEFT " " }
  122.     else local MEFT "*"
  123.     if "`obs'"!=""  { local OBS " " }
  124.     else local OBS "*"
  125.     if "`size'"!="" { local SIZE " " }
  126.     else local SIZE "*"
  127.  
  128. /* Print out column headers of table 2. */
  129.  
  130.     DashLine
  131.     Colhead `level' `or' * * * "`DEFF'" "`DEFT'" "`MEFF'" "`MEFT'"
  132.  
  133. /* Print out body of table 2. */
  134.  
  135.     DashLine 10
  136.  
  137.     local i 1
  138.     while `i' <= `dim' {
  139.         Body `i' `b' `V' `t' `or' * * * /*
  140.         */    "`DEFF'" "`DEFT'" "`MEFF'" "`MEFT'"
  141.         local i = `i' + 1
  142.     }
  143.  
  144.     DashLine
  145.  
  146.     FootNote
  147. end
  148.  
  149. program define DashLine
  150.     if "`1'"=="" {
  151.         di in gr _dup(78) "-"
  152.         exit
  153.     }
  154.     local dash1 = `1' - 1
  155.     local dash2 = 78 - `1'
  156.     di in gr _dup(`dash1') "-" "+" _dup(`dash2') "-"
  157. end
  158.  
  159. program define FootNote
  160.     if "$S_E_cmd"=="svymlog" & "$S_E_base"!="" {
  161.         di in blu "(Outcome $S_E_depv==$S_E_base is the " /*
  162.         */ "comparison group)"
  163.         if "$S_E_fpc"!="" { di /* newline */ }
  164.     }
  165.  
  166.     if "$S_E_fpc"!="" { /* print FPC note */
  167.         #delimit ;
  168.         di in blu "Finite population correction (FPC) assumes "
  169.               "simple random sampling without " _n
  170.               "replacement of PSUs within each stratum with no "
  171.               "subsampling within PSUs." ;
  172.         #delimit cr
  173.     }
  174.  
  175.     if "$S_E_fail$S_E_succ"!="" {
  176.         if "$S_E_fail"!="" { local nfail "$S_E_fail" }
  177.         else             local nfail 0
  178.         if "$S_E_succ"!="" { local nsucc "$S_E_succ" }
  179.         else             local nsucc 0
  180.         if `nfail'==1 { local failure "failure" }
  181.         else        local failure "failures"
  182.         if `nsucc'==1 { local success "success" }
  183.         else        local success "successes"
  184.         di _n in blu "Note: `nfail' `failure' and `nsucc' " /*
  185.         */ "`success' completely determined."
  186.     }
  187. end
  188.  
  189. program define Colhead
  190.     local level "`1'"
  191.     local or    "`2'"
  192.     macro shift 2
  193.     if   "$S_E_cmd"=="svymean" | "$S_E_cmd"=="svyratio" /*
  194.     */ | "$S_E_cmd"=="svytotal" {
  195.         local col1 "  Estimate"
  196.     }
  197.     else if "`or'"=="or"  { local col1 "Odds Ratio" }
  198.     else if "`or'"=="rrr" { local col1 "       RRR" }
  199.     else                    local col1 "     Coef."
  200.  
  201.     `1' local head " `col1'    Std. Err."
  202.     `2' local head "`head'       t     P>|t|  "
  203.     `2' local s " "
  204.     `3' local head "`head'`s'   [`level'% Conf. Interval]"
  205.     `3' local s " "
  206.     `4' local head "`head'`s'       Deff"
  207.     `4' local s " "
  208.     `5' local head "`head'`s'       Deft"
  209.     `5' local s " "
  210.     `6' local head "`head'`s'       Meff"
  211.     `6' local s " "
  212.     `7' local head "`head'`s'       Meft"
  213.  
  214.     local col = 9 - length("$S_E_depv")
  215.     di in gr _col(`col') "$S_E_depv |" "`head'"
  216. end
  217.  
  218. program define Body
  219.     local i  "`1'"
  220.     local b  "`2'"
  221.     local V  "`3'"
  222.     local t  "`4'"
  223.     local or "`5'"
  224.     macro shift 5
  225.     local s 2
  226.     tempname v
  227.  
  228.     local colname : colnames(`b')
  229.     local coli : word `i' of `colname'
  230.  
  231.     if "$S_E_cmd"=="svymlog" {
  232.         if "`or'"=="rrr" & "`coli'"=="_cons" { exit }
  233.         local eqlen = colsof(`b')/($S_E_ncat-1)
  234.         if `eqlen'==1 | mod(`i',`eqlen')==1 {
  235.             if `i' > 1 { DashLine 10 }
  236.             tempname A
  237.             matrix `A' = `b'[1,`i']
  238.             local eqname : coleq(`A')
  239.             di in ye "`eqname'" _col(10) in gr "|"
  240.         }
  241.     }
  242.     else if "$S_E_cmd"=="svyolog" | "$S_E_cmd"=="svyoprob" {
  243.         local icut = `i' - colsof(`b') + $S_E_ncat - 1
  244.         if `icut' >= 1 {
  245.             if `icut' == 1 { DashLine 10 }
  246.             local coli "_cut`icut'"
  247.         }
  248.     }
  249.  
  250.     local col = 9 - length("`coli'")
  251.     di in gr _col(`col') "`coli' |" _c
  252.  
  253.     if `V'[`i',`i']==0 {
  254.         if `b'[1,`i']==0 {
  255.             di in ye " (dropped)"
  256.             exit
  257.         }
  258.         scalar `v' = .
  259.     }
  260.     else scalar `v' = `V'[`i',`i']
  261.  
  262.     if "`or'"!="no" {
  263.         local exp "exp"
  264.         local eb "exp(`b'[1,`i'])*"
  265.     }
  266.  
  267.     `1' local body : di _s(2) %9.0g `exp'(`b'[1,`i']) _s(3) %9.0g /*
  268.     */         `eb'sqrt(`v')
  269.     `1' local s 3
  270.  
  271.     `2' local x : di _s(3) %8.3f `b'[1,`i']/sqrt(`v') /*
  272.     */  %8.3f tprob($S_E_npsu-$S_E_nstr,`b'[1,`i']/sqrt(`v')) _s(2)
  273.     `2' local body "`body'`x'"
  274.  
  275.     `3' local x : di _s(3) %9.0g `exp'(`b'[1,`i']-`t'*sqrt(`v')) /*
  276.     */         _s(3) %9.0g `exp'(`b'[1,`i']+`t'*sqrt(`v'))
  277.     `3' local body "`body'`x'"
  278.  
  279.     `4' local x : di _s(`s') %9.0g cond(S_E_deff[1,`i']!=0, /*
  280.     */                S_E_deff[1,`i'],.)
  281.     `4' local body "`body'`x'"
  282.     `4' local s 3
  283.  
  284.     `5' local x : di _s(`s') %9.0g cond(S_E_deft[1,`i']!=0, /*
  285.     */                S_E_deft[1,`i'],.)
  286.     `5' local body "`body'`x'"
  287.     `5' local s 3
  288.  
  289.     `6' local x : di _s(`s') %9.0g cond(S_E_meft[1,`i']!=0, /*
  290.     */                S_E_meft[1,`i']^2,.)
  291.     `6' local body "`body'`x'"
  292.     `6' local s 3
  293.  
  294.     `7' local x : di _s(`s') %9.0g cond(S_E_meft[1,`i']!=0, /*
  295.     */                S_E_meft[1,`i'],.)
  296.     `7' local body "`body'`x'"
  297.     `7' local s 3
  298.  
  299.     di in ye "`body'"
  300. end
  301.  
  302. program define Header /* display header */
  303.     local wgt    "$S_E_wgt"
  304.     local exp    "$S_E_exp"
  305.     local strata "$S_E_str"
  306.     local psu    "$S_E_psu"
  307.     if "`wgt'"    == "" { local wgt    "pweight"        }
  308.     if "`exp'"    == "" { local exp    "<none>"         }
  309.     if "`strata'" == "" { local strata "<one>"          }
  310.     if "`psu'"    == "" { local psu    "<observations>" }
  311.  
  312. /* Set denominator df for F statistic and other stuff for F display. */
  313.  
  314.     if "$S_E_adj"=="" { /* adjusted (default) */
  315.         local df = $S_E_npsu - $S_E_nstr - $S_E_mdf + 1
  316.     }
  317.     else     local df = $S_E_npsu - $S_E_nstr
  318.  
  319.     if $S_E_f >= 10000 { local fmtf "g" }
  320.     else local fmtf "f"
  321.  
  322. /* Set up display for subpop() option obs and size. */
  323.  
  324.     if "$S_E_osub"!="" {
  325.         if "$S_E_fpc"=="" & "$S_E_r2"=="" { /* print up one line */
  326.             local left5a "Subpopulation no. of obs = "
  327.             local left5b : di %9.0f $S_E_osub
  328.             local left6a "Subpopulation size       ="
  329.             local left6b : di %10.0g $S_E_nsub
  330.         }
  331.         else {
  332.             local left6a "Subpopulation no. of obs = "
  333.             local left6b : di %9.0f $S_E_osub
  334.             local left7a "Subpopulation size       ="
  335.             local left7b : di %10.0g $S_E_nsub
  336.         }
  337.     }
  338.  
  339. /* Set up display for R-squared. */
  340.  
  341.     if "$S_E_r2"!="" {
  342.         local right7a "R-squared        = "
  343.         local right7b : di %9.4f $S_E_r2
  344.     }
  345.  
  346. /* Title. */
  347.  
  348.     if "$S_E_cmd"=="svyreg" {
  349.         di _n in gr "Survey linear regression" _n
  350.     }
  351.     else if "$S_E_cmd"=="svylogit" {
  352.         di _n in gr "Survey logistic regression" _n
  353.     }
  354.     else if "$S_E_cmd"=="svyprobt" {
  355.         di _n in gr "Survey probit regression" _n
  356.     }
  357.     else if "$S_E_cmd"=="svyolog" {
  358.         di _n in gr "Survey ordered logistic regression" _n
  359.     }
  360.     else if "$S_E_cmd"=="svyoprob" {
  361.         di _n in gr "Survey ordered probit regression" _n
  362.     }
  363.     else if "$S_E_cmd"=="svymlog" {
  364.         di _n in gr "Survey multinomial logistic regression" _n
  365.     }
  366.  
  367.         /* Note: _rmcoll (not used by svyreg, svylogit, svyprobt)
  368.                  in svy_preg.ado always prints out a blank line.
  369.         */
  370.  
  371. /* Print lines 1-4 (see notes at end of file). */
  372.  
  373.     #delimit ;
  374.     di in gr "`wgt':  `exp'"
  375.        in gr _col(51) "Number of obs" _col(68) "= "
  376.        in ye %9.0f $S_E_nobs _n
  377.        in gr "Strata:   `strata'"
  378.        in gr _col(51) "Number of strata" _col(68) "= "
  379.        in ye %9.0f $S_E_nstr _n
  380.        in gr "PSU:      `psu'"
  381.        in gr _col(51) "Number of PSUs" _col(68) "= "
  382.        in ye %9.0f $S_E_npsu ;
  383.  
  384.     if "$S_E_fpc"!="" {
  385.         di in gr "FPC:      $S_E_fpc"
  386.            in gr _col(51) "Population size" _col(68) "="
  387.            in ye %10.0g $S_E_npop
  388.     } ;
  389.     else    di in gr _col(51) "Population size" _col(68) "="
  390.            in ye %10.0g $S_E_npop ;
  391.  
  392. /* Print lines 5-7 (see notes at end of file). */
  393.  
  394.     di in gr "`left5a'" in ye "`left5b'"
  395.        in gr _col(51) "F(" in ye %4.0f $S_E_mdf in gr ","
  396.        in ye %7.0f `df' in gr ")" _col(68) "= "
  397.        in ye %9.2`fmtf' $S_E_f _n
  398.        in gr "`left6a'" in ye "`left6b'"
  399.        in gr _col(51) "Prob > F" _col(68) "= "
  400.        in ye %9.4f fprob($S_E_mdf,`df',$S_E_f) ;
  401.  
  402.     if "`left7a'`right7a'"!="" { ;
  403.         di in gr "`left7a'" in ye "`left7b'"
  404.            in gr _col(51) "`right7a'" in ye "`right7b'" ;
  405.     } ;
  406.  
  407.     di ;
  408. end ;
  409. exit ;
  410.  
  411. There are 4 possible arrangements for the header:
  412.  
  413. ------------------------------------------------------------------------------
  414. pweight:  weight                                  Number of obs    =        21
  415. Strata:   strata                                  Number of strata =         4
  416. PSU:      psu                                     Number of PSUs   =        14
  417. FPC:      Nh                                      Population size  =       189
  418.                                                   F(   2,      9)  =      3.43
  419. Subpopulation no. of obs =         8              Prob > F         =    0.0780
  420. Subpopulation size       =        82              R-squared        =    0.4129
  421. ------------------------------------------------------------------------------
  422. pweight:  weight                                  Number of obs    =        21
  423. Strata:   strata                                  Number of strata =         4
  424. PSU:      psu                                     Number of PSUs   =        14
  425.                                                   Population size  =       189
  426.                                                   F(   2,      9)  =      3.11
  427. Subpopulation no. of obs =         8              Prob > F         =    0.0937
  428. Subpopulation size       =        82              R-squared        =    0.4129
  429. ------------------------------------------------------------------------------
  430. pweight:  weight                                  Number of obs    =        21
  431. Strata:   strata                                  Number of strata =         4
  432. PSU:      psu                                     Number of PSUs   =        14
  433. FPC:      Nh                                      Population size  =       189
  434.                                                   F(   2,      9)  =      3.43
  435. Subpopulation no. of obs =         8              Prob > F         =    0.0780
  436. Subpopulation size       =        82
  437. ------------------------------------------------------------------------------
  438. pweight:  weight                                  Number of obs    =        21
  439. Strata:   strata                                  Number of strata =         4
  440. PSU:      psu                                     Number of PSUs   =        14
  441.                                                   Population size  =       189
  442. Subpopulation no. of obs =         8              F(   2,      9)  =      3.11
  443. Subpopulation size       =        82              Prob > F         =    0.0937
  444. ------------------------------------------------------------------------------
  445.  
  446. <end of file>
  447.